package com.maxd.respository.commodity;

import com.maxd.model.Commodity;
import com.maxd.model.CommodityExquisite;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CommodityRepository extends Repository<Commodity, Long> {

    @Query(value = "select * from commodity where id=:id",nativeQuery = true)
    Commodity selectById(@Param("id") Long id);


    @Query(value = "select * from commodity where id=:userId",
            countQuery="select count(*) from commodity where id=:userId"
            ,nativeQuery = true)
    Page<Commodity> selectByUserId(@Param("userId") Long userId, Pageable pageable);

    @Query(value = "select * from commodity",
            countQuery="select count(*) from commodity "
            ,nativeQuery = true)
    Page<Commodity> selectCommodityList(Pageable pageable);

    @Query(value = "select * from commodity where itemid=:itemid limit 1",
            countQuery="select count(*) from commodity where itemid=:itemid limit 1"
            ,nativeQuery = true)
    Commodity selectCommodityList(@Param("itemid") String itemid);


}
